home *** CD-ROM | disk | FTP | other *** search
- /*
- * $Workfile:: Template.c $
- * $Revision:: 3 $
- *
- * $Author:: Buck Rogers $
- * $Modtime:: 29.10.1997 17:52 Uhr $
- *
- * $History:: Template.c $
- *
- * ***************** Version 3 *****************
- * User: Buck Rogers Date: 29.10.1997 Time: 17:53 Uhr
- * Updated in $/BSNG/Plugins/BSNG SDK/BSNG Template
- * updated source to show how to make use of the new 'errorText' variable
- *
- * ***************** Version 2 *****************
- * User: Buck Rogers Date: 08.10.1997 Time: 02:02 Uhr
- * Updated in $/BSNG/Plugins/BSNG SDK/BSNG Template
- * changed lf to cr in list generation so Mac compatible output is created
- *
- * ***************** Version 1 *****************
- * User: Buck Rogers Date: 06.10.1997 Time: 06:25 Uhr
- * Created in $/BSNG/Plugins/BSNG SDK/BSNG Template
- * Adding subproject 'BSNG Template' to '$/BSNG/Plugins/BSNG SDK'
- *
- * $NoKeywords:: $
- */
-
-
- #include <MixedMode.h>
- #include <A4Stuff.h>
-
- #include "standard utils.h"
- #include "UltraU.h"
- #include "BSNG API.h"
- #include "BSNG Product.h"
- #include "Generate.h"
-
- /* don't touch this __procinfo definition or the calls from native code will crash the machine */
-
- ProcInfoType __procinfo = kThinkCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(BSNGParamBlockPtr)));
-
- /* these should be moved into standard utils.h */
- OSErr WriteData(BSNGParamBlockPtr inData, const char* inText, long inLength);
- OSErr WriteCString(BSNGParamBlockPtr inData, const char* inString);
- OSErr WritePString(BSNGParamBlockPtr inData, StringPtr inString);
-
-
- /* function prototypes for ANSI C */
-
- static void DoInit(BSNGParamBlockPtr inData);
- static Boolean DoValidate(BSNGParamBlockPtr inData);
- static void DoCalc(BSNGParamBlockPtr inData);
- static void DoRandomCalc(BSNGParamBlockPtr inData);
- static Boolean DoAddRandomsToList(BSNGParamBlockPtr inData);
- static void DoItemHit(BSNGParamBlockPtr inData);
- static void DoCleanup(BSNGParamBlockPtr inData);
- void main(BSNGParamBlockPtr inData);
-
-
- /* here is where the fun starts :-) */
-
- static void DoInit(BSNGParamBlockPtr inData)
- {
- /* Initialize the Ultra Random Number generator (optional, use MacOS random functions otherwise) */
-
- Ultra_seed1 = inData->randSeed1;
- Ultra_seed2 = inData->randSeed2;
- Ultra_Init();
-
- /* Give the BSNG App the informations if your plugin can do random calculations and if it can write
- to the serial number list */
-
- inData->wantsRandomButton = true;
- inData->canAddToSNList = true;
-
- /* Fill out the default values; all values are initially empty. */
- UserFillDefaults(inData);
-
- /* Tell the BSNG App if the initialisation was successful (it was in our case) */
-
- inData->error = errExtNoErr;
- inData->errorInItem = 0;
- } /* DoInit */
-
-
- static Boolean DoValidate(BSNGParamBlockPtr inData)
- {
- inData->errorText[0] = 0;
- inData->error = errExtNoErr;
-
- if (UserValidate(inData) == false)
- {
- inData->error = errExtIncorrectValue;
- return (false);
- }
-
- return (true);
- } /* DoValidate */
-
-
- static void DoCalc(BSNGParamBlockPtr inData)
- {
- StringPtr result;
- short resultIndex;
-
- /* do your calculations here */
- resultIndex = UserCalculate(inData);
- if (resultIndex >= kItemValue1 && resultIndex <= kItemValue10)
- {
- result = inData->itemValue[resultIndex];
-
- ZeroScrap();
- PutScrap(result[0], 'TEXT', result + 1);
- }
-
- } /* DoCalc */
-
-
- static void DoRandomCalc(BSNGParamBlockPtr inData)
- {
- /* prepare random calculations here */
- UserRandomize(inData);
-
- DoCalc(inData);
- } /* DoRandomCalc */
-
-
- static const char gEquals[] = "================================"
- "================================"
- "================================"
- "================================";
-
- static Boolean DoAddRandomsToList(BSNGParamBlockPtr inData)
- {
- long count = 0L;
- short i = 0;
- OSErr err = noErr;
-
- if (WriteCString(inData, PROGRAM_NAME) != noErr)
- goto failed;
-
- if (WriteCString(inData, "\r") != noErr)
- goto failed;
-
- if (WriteData(inData, gEquals, cStrLen(PROGRAM_NAME, 0x7FFFFFFF)) != noErr)
- goto failed;
-
- if (WriteCString(inData, "\r") != noErr)
- goto failed;
-
- /* write your header to the number list */
-
- if (UserWriteListHeader(inData) != noErr)
- goto failed;
-
- /* create numOfListNumbers random serial numbers and write them to the list */
- /* if you create a name-based generator please make sure that you create at least one number */
- /* using the name, company and/or numCopies informations. You could create more name-based numbers */
- /* by using your own name/company database */
-
- for (i = 0; i < inData->numOfListNumbers; i++)
- {
- DoRandomCalc(inData);
-
- /* write results to list here */
- if (UserWriteListNumber(inData) != noErr)
- goto failed;
- }
-
- /* don't forget this last newline */
-
- if (WriteCString(inData, "\r") != noErr)
- goto failed;
-
- return (true);
-
- failed:
- return false;
-
- } /* DoAddRandomsToList */
-
-
- static void DoItemHit(BSNGParamBlockPtr inData)
- {
- switch (inData->itemMessage)
- {
- case (300000):
-
- /* the "About this plugin" button was pressed, do whatever you want, I just display a small Alert here */
-
- NoteAlert(1000, nil);
- break;
-
- default:
- break;
- }
- } /* DoItemHit */
-
-
- static void DoCleanup(BSNGParamBlockPtr inData)
- {
- #pragma unused (inData)
-
- /* we didn't allocate any memory in DoInit, so we can leave this empty, otherwise it would be a VERY good idea
- to deallocate/dispose etc. everything we allocated during our work. If you don't do that we have a nice memory leak */
-
- } /* DoCleanup */
-
-
- void main(BSNGParamBlockPtr inData)
- {
- #if (!GENERATINGPOWERPC)
- EnterCodeResource();
- #endif
-
- /* the message dispatcher */
-
- switch(inData->theMessage)
- {
- case (msgExtInit):
- DoInit(inData);
- break;
-
- case (msgExtCalcHit):
-
- if (DoValidate(inData))
- {
- DoCalc(inData);
- }
-
- break;
-
- case (msgExtRandomHit):
- DoRandomCalc(inData);
- break;
-
- case (msgExtCreateRandom):
-
- /* report to the BSNG App if your list entry was written ok or if we had an error */
-
- if (DoAddRandomsToList(inData))
- {
- inData->error = errExtNoErr;
- }
- else
- {
- inData->error = errExtWritingToList;
- }
-
- break;
-
- case (msgExtItemHit):
- DoItemHit(inData);
- break;
-
- case (msgExtCleanup):
- DoCleanup(inData);
- break;
-
- default:
- break;
- }
-
- #if (!GENERATINGPOWERPC)
- ExitCodeResource();
- #endif
- } /* main */
-
-
- /* As mentioned at the top of the file, these should be moved to standard utils.c */
- OSErr WriteData(BSNGParamBlockPtr inData, const char* inText, long inLength)
- {
- long count = inLength;
-
- return FSWrite(inData->outputRefNum, &count, inText);
- }
-
- OSErr WriteCString(BSNGParamBlockPtr inData, const char* inString)
- {
- return WriteData(inData, inString, cStrLen((const Ptr) inString, 0x7FFFFFFF));
- }
-
- OSErr WritePString(BSNGParamBlockPtr inData, StringPtr inString)
- {
- return WriteData(inData, (const char*) (inString + 1), inString[0]);
- }
-
-